# -*- coding: UTF-8 -*-

from Code.Binder.sc_topic import *
from Code.Binder.sc_proxy import get_active_data_binder, get_passive_data_binder
from Code.View.sc_app import app_gate
from Code.View.sc_module import WidgetTip
from Code.View.Datamation.sc_provide import view_gate


def init():
    # 界面变更事件绑定数据ID #
    active_binder = get_active_data_binder()
    active_binder.bind(view_gate.app_close_data.get_provider(), VIEW_NOTIFY_APP_CLOSE_DATA)
    active_binder.bind(view_gate.exception_data.get_provider(), VIEW_NOTIFY_EXCEPTION_DATA)
    active_binder.bind(view_gate.try_login_data.get_provider(), VIEW_NOTIFY_TRY_LOGIN_DATA)
    active_binder.bind(view_gate.new_login_data.get_provider(), VIEW_NOTIFY_NEW_LOGIN_DATA)
    active_binder.bind(view_gate.del_login_data.get_provider(), VIEW_NOTIFY_DEL_LOGIN_DATA)
    active_binder.bind(view_gate.add_image_data.get_provider(), VIEW_NOTIFY_ADD_IMAGE_DATA)
    active_binder.bind(view_gate.del_image_data.get_provider(), VIEW_NOTIFY_DEL_IMAGE_DATA)
    active_binder.bind(view_gate.start_exec_data.get_provider(), VIEW_NOTIFY_START_EXEC_DATA)
    active_binder.bind(view_gate.stop_exec_data.get_provider(), VIEW_NOTIFY_STOP_EXEC_DATA)
    active_binder.bind(view_gate.update_settings_data.get_provider(), VIEW_NOTIFY_UPDATE_SETTINGS_DATA)
    active_binder.bind(view_gate.make_plot_pic_data.get_provider(), VIEW_NOTIFY_MAKE_PLOT_PIC_DATA)
    active_binder.bind(view_gate.single_start_data.get_provider(), VIEW_NOTIFY_SINGLE_START_DATA)
    active_binder.bind(view_gate.single_upload_data.get_provider(), VIEW_NOTIFY_SINGLE_UPLOAD_DATA)
    active_binder.bind(view_gate.single_download_data.get_provider(), VIEW_NOTIFY_SINGLE_DOWNLOAD_DATA)

    # 数据变更事件绑定界面处理函数 #
    passive_binder = get_passive_data_binder()
    passive_binder.bind(MODEL_NOTIFY_EXCEPTION_DATA, WidgetTip.error)
    passive_binder.bind(MODEL_NOTIFY_APP_TITLE_DATA, app_gate.update_app_title)
    passive_binder.bind(MODEL_NOTIFY_APP_TREES_DATA, app_gate.update_app_trees)
    passive_binder.bind(MODEL_NOTIFY_APP_WIDGETS_DATA, app_gate.update_app_widgets)
    passive_binder.bind(MODEL_NOTIFY_TRY_LOGIN_RETURN_DATA, app_gate.update_try_login_return)
    passive_binder.bind(MODEL_NOTIFY_NEW_LOGIN_RETURN_DATA, app_gate.update_new_login_return)
    passive_binder.bind(MODEL_NOTIFY_LOGIN_STATE_DATA, app_gate.update_login_state)
    passive_binder.bind(MODEL_NOTIFY_UPDATE_INFOTEXT_DATA, app_gate.update_infotext_data)
    passive_binder.bind(MODEL_NOTIFY_UPDATE_PROGRESS_DATA, app_gate.update_progress_data)
    passive_binder.bind(MODEL_NOTIFY_UPDATE_PRINTOUT_DATA, app_gate.update_printout_data)
    passive_binder.bind(MODEL_NOTIFY_UPDATE_WIDGETS_DATA, app_gate.update_widgets_data)
    passive_binder.bind(MODEL_NOTIFY_SINGLE_START_RESULT_DATA, app_gate.single_start_result)
    passive_binder.bind(MODEL_NOTIFY_SINGLE_UPLOAD_RESULT_DATA, app_gate.single_upload_result)
    passive_binder.bind(MODEL_NOTIFY_SINGLE_DOWNLOAD_RESULT_DATA, app_gate.single_download_result)

    return True


def app_run():
    app_gate.run()
